<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/20 0020
 * Time: 17:26
 */

namespace app\model\model;


class Authmenu extends Base
{
    /**
     * 获取一个
     * */
    public function getMenuListRankTwo($rank){
        return $this->where(['rank'=>$rank])->order('sort asc')->select();
    }
    /**
     * 获得菜单列表
     * */
    public function getMenuListRankOne($type){
        $arr = $this->where(['type'=>$type])->order('sort asc')->select();
        $menulist = [];
        foreach ($arr as $k=>$v){
            $menulist[$k] = [
                'id'=>$v['id'],
                'name'=>$v['name'],
                'url'=>$v['url'],
                'type'=>$v['type']
            ];
            $dataTwo = $this->getMenuListRankTwo($v['id']);
            foreach ($dataTwo as $key=>$value){
                $menulist[$k]['data'][$key]=[
                    'id'=>$value['id'],
                    'name'=>$value['name'],
                    'url'=>$value['url'],
                    'type'=>$v['type']
                ];
            }
        }
        return $menulist;
    }
    /**
     * 获得菜单列表
     * */
    public function getMenuListRankAll(){
        $arr = $this->order('sort asc')->select();
        $menulist = [];
        foreach ($arr as $k=>$v){
            $menulist[$k] = [
                'id'=>$v['id'],
                'name'=>$v['name'],
                'url'=>$v['url'],
                'type'=>$v['type']
            ];
            $dataTwo = $this->getMenuListRankTwo($v['id']);
            foreach ($dataTwo as $key=>$value){
                $menulist[$k]['data'][$key]=[
                    'id'=>$value['id'],
                    'name'=>$value['name'],
                    'url'=>$value['url'],
                    'type'=>$v['type']
                ];
            }
        }
        return $menulist;
    }

}